package com.straw.hat.collecion.loop;

import com.straw.hat.common.util.RandomNumGenerator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @company: 鲸灵科技
 * @author: qiyue@webuy.ai
 * @date: 2019/10/11
 * @time: 2:37 下午
 */
public class LoopStudy implements Iterator {


    private int cursor;
    private int size;
    private int [] table ;

    private LoopStudy(){};

    public static LoopStudy build(int [] table) {
        LoopStudy loopStudy = new LoopStudy();
        loopStudy.table = table;
        loopStudy.size = table.length;
        return loopStudy;
    }



    @Override
    public boolean hasNext() {
        return cursor < this.size;
    }

    @Override
    public Object next() {
        return this.table[cursor++];
    }

    @Override
    public void remove() {
        int len = size - cursor - 1;
        System.arraycopy(table, cursor+1, table,cursor,len);
        size--;
    }


    public static void main(String[] args) {
        /*数组形*/
//        int[] ints = RandomNumGenerator.generator(100000000);
//        LoopStudy loopStudy = build(ints);
//        int length = ints.length;
//        long start1 = System.currentTimeMillis();
//        for (int i = 0 ; i < length ; i++) {
//            System.out.print("");
//        }
//        System.out.println("spend time : "+ Long.valueOf(System.currentTimeMillis()-start1));
//        long start2 = System.currentTimeMillis();
//        while(loopStudy.hasNext()){
//            loopStudy.next();
//            System.out.print("");
//        }
//        System.out.println("spend time : "+ Long.valueOf(System.currentTimeMillis()-start2));
        /*集合形*/
        List<Integer> integers = new ArrayList<>(10000);
        int[] ints = RandomNumGenerator.generator(10000);
        int i = 0;
        while (i < 10000) {
            integers.add(ints[i++]);
        }
        

    }
}
